package org.codeart.factory.scheme02.service.impl;

import cn.hutool.json.JSONUtil;
import org.codeart.factory.scheme02.pojo.AwardInfo;
import org.codeart.factory.scheme02.pojo.GiftInfo;
import org.codeart.factory.scheme02.pojo.ResponseInfo;
import org.codeart.factory.scheme02.service.IFreeGoods;

import java.util.Map;
import java.util.UUID;

/**
 * 小礼品发放服务
 */
public class GiftFreeGoods implements IFreeGoods {

    @Override
    public ResponseInfo sendFreeGoods(AwardInfo info) {
        GiftInfo giftInfo = new GiftInfo();
        Map<String, String> extraInfo = info.getExtraInfo();
        giftInfo.setUsername(extraInfo.get("username"))
                .setPhone(extraInfo.get("phone"))
                .setAddress(extraInfo.get("address"))
                .setOrderId(UUID.randomUUID().toString());
        System.out.println("小礼品发放成功, 请注意接收: " + JSONUtil.toJsonPrettyStr(giftInfo));
        return new ResponseInfo("200", "小礼品发放成功", giftInfo);
    }
}
